package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.UserInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Query;

/**
 * @Author 请不要叫我高司令
 * @Date 2022/3/14 18:41
 * @Version 1.0
 */

@DubboService
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {

        userInfoMapper.insert(userInfo);

    }

    @Override
    public void update(UserInfo userInfo) {

        userInfoMapper.updateById(userInfo);

    }

    @Override
    public UserInfo findById(Long userId) {

        return userInfoMapper.selectById(userId);

    }

    @Override
    public PageBeanVo findUserInfoByPage(Integer pageNum, Integer pageSize) {

        // 1.开启分页
        Page<UserInfo> page = new Page<>(pageNum, pageSize);
        // 2.分页查询
        page = userInfoMapper.selectPage(page, null);
        // 3.封装pageBeanVo
        return new PageBeanVo(pageNum, pageSize, page.getTotal(), page.getRecords());
    }
}
